#pragma once

#include <vulkan\vulkan_raii.hpp>
#include <Core/Context/LumineContext.hpp>

namespace Lumine
{
    class LumineSwapchain
    {
    private:
        GLFWwindow * m_window;
        vk::raii::SwapchainKHR m_swapchain = nullptr;
        std::vector<vk::Image> m_swapchainImages;
        std::vector<vk::raii::ImageView> m_swapchainImageViews;
        vk::Format m_swapchainImageFormat = vk::Format::eUndefined;
        vk::Extent2D m_swapchainExtent;
        vk::SwapchainCreateInfoKHR createInfo;

        void createSwapchain(GLFWwindow *window);
        void createImageViews();

    public:
        LumineSwapchain() = default;
        // 禁用拷贝构造和赋值运算符
        LumineSwapchain(const LumineSwapchain &) = delete;
        LumineSwapchain &operator=(const LumineSwapchain &) = delete;

        LumineSwapchain(LumineSwapchain &&) = default;
        LumineSwapchain &operator=(LumineSwapchain &&) = default;

        void Initialize(GLFWwindow *window,vk::SwapchainKHR old);

        void cleanup();

        void recreate(GLFWwindow* window);

        vk::SwapchainKHR GetHandle() const { return *m_swapchain; }

        const std::vector<vk::Image> SwapchainImages() const { return m_swapchainImages; }

        const std::vector<vk::raii::ImageView> &SwapchainImageViews() const { return m_swapchainImageViews; }

        const vk::Format &ImageFormat() const { return m_swapchainImageFormat; }

        const vk::Extent2D &Extent() const
        {
            return m_swapchainExtent;
        }

        const vk::raii::SwapchainKHR &Swapchain() const
        {
            return m_swapchain;
        }
    };
}